# 空文件，标记这是一个 Python 包 

from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
from .config import config
import os

# 创建数据库实例
db = SQLAlchemy()

def create_app(config_name=None):
    """创建 Flask 应用"""
    if config_name is None:
        config_name = os.getenv('FLASK_ENV', 'default')
    
    app = Flask(__name__)
    
    # 初始化配置
    config[config_name].init_app(app)
    
    # 初始化扩展
    db.init_app(app)
    
    # 注册根路由
    @app.route('/')
    def index():
        return jsonify({
            "status": "ok",
            "message": "Welcome to AgileCodeAI API"
        })
    
    # 注册 Blueprint
    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')
    
    return app 